﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace G.Service.APITest
{
    public partial class UploadDLL : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUploadDLL_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                var fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
                if (fileExt == ".dll")
                {
                    try
                    {
                        if (!System.IO.Directory.Exists(Server.MapPath("API_DLL")))
                        {
                            System.IO.Directory.CreateDirectory(Server.MapPath("API_DLL"));
                        }
                        string path = Server.MapPath("API_DLL") + "\\" + FileUpload1.FileName;
                        if (!System.IO.File.Exists(path))
                        {
                            FileUpload1.SaveAs(path);
                            Label1.Text = "客户端路径：" + FileUpload1.PostedFile.FileName + "<br>" +

                                          "文件名：" + System.IO.Path.GetFileName(FileUpload1.FileName) + "<br>" +

                                          "文件扩展名：" + System.IO.Path.GetExtension(FileUpload1.FileName) + "<br>" +

                                          "文件大小：" + (FileUpload1.PostedFile.ContentLength / 1024) + " KB<br>" +

                                          "文件MIME类型：" + FileUpload1.PostedFile.ContentType + "<br>" +

                                          "保存路径：" + Server.MapPath("upload") + "\\" + FileUpload1.FileName;
                        }
                        else
                        {
                            Label1.Text = "已经存在该文件！";
                        }

                    }

                    catch (Exception ex)
                    {

                        Label1.Text = "发生错误：" + ex.Message.ToString();

                    }
                }
            }
        }
    }
}